<?php
$v_staff_id =  $_SESSION['staff_id'];
if (!isset($_SESSION['staff_id'])||is_null(($_SESSION['staff_id']))){
	$v_staff_id = 1;
}
$v_recordtype_filter_list = "";
if(isset($_REQUEST['hdn_recordtype_filter_list'])){
	$v_recordtype_filter_list = $_REQUEST['hdn_recordtype_filter_list'];
}
$v_recordtype_filter = $_SESSION['onegate_current_recordtype'];		// nieuvv--270808---loai ho so

//echo '_ISA_CURRENT_MODUL_CODE' . $_ISA_CURRENT_MODUL_CODE; exit;
switch($_ISA_CURRENT_MODUL_CODE) {
	case "RECEIVE_RESULT";
		$v_receiver = 1;
		$v_handle = -1;
		$v_handle_leader = -1;
		$v_approve_leader = -1;
		$v_is_view_on_net = -1;
		$v_is_register_on_net = -1;
		break;
	case "HANDLE";
		$v_receiver = -1;
		// Neu NSD cho co quyen cap nhat tien do cong viec cua mot loai ho so thi gan bien $v_handle = 2; 
		//trong truong hop nguoc lai thi hien thi voi day du quyen cua mot can bo thu ly nhu: Cap nhat tien do cong viec,
		// cap nhat giay phep, trinh lanh dao,...
		//if(onegate_is_permission_update_rate_of_progress_for_recordtype($v_staff_id,0,$_SESSION["recordtype"])){
		//	$v_handle = 2;
		//}else{
			$v_handle = 1;
		//}		
		$v_handle_leader = -1;
		$v_approve_leader = -1;
		$v_is_view_on_net = -1;
		$v_is_register_on_net = -1;
		break;
	case "APPROVING";
		//echo 'vao day.......';
		$v_receiver = -1;
		$v_handle = -1;
		$v_handle_leader = 0;
		$v_approve_leader = 0;
		$v_is_view_on_net = -1;
		$v_is_register_on_net = -1;
		break;
	case "APPROVING_NET";
		$v_receiver = 1;
		$v_handle = -1;
		$v_handle_leader = -1;
		$v_approve_leader = -1;
		$v_is_view_on_net = -1;
		$v_is_register_on_net = 1;
		break;
	default:
		$v_receiver = -1;
		$v_handle = -1;
		$v_handle_leader = -1;
		$v_approve_leader = -1;
		$v_is_view_on_net = -1;
		$v_is_register_on_net = -1;
		break;
}
if (!is_null($v_is_view_record_on_net)&& $v_is_view_record_on_net>0){
	$v_is_view_on_net = $v_is_view_record_on_net;
}
if (!is_null($v_is_register_record_on_net)&& $v_is_register_record_on_net>0){
	$v_is_register_on_net = $v_is_register_record_on_net;
}
//Neu co quyen Xem tat ca cac loai ho so 
if ($v_is_granted_view_record){
	$v_receiver = -1;
	$v_handle = -1;
	$v_handle_leader = -1;
	$v_approve_leader = -1;
	$v_is_view_on_net = -1;
	$v_is_register_on_net = -1;
}
if(_is_sqlserver()){
	$sql = "Exec ONEGATE_RecordtypeGetAllByStaff_Vunh";
	$sql = $sql . " " . $v_staff_id;
	$sql = $sql . "," . $v_receiver;
	$sql = $sql . "," . $v_handle;
	$sql = $sql . "," . $v_handle_leader;
	$sql = $sql . "," . $v_approve_leader;
	$sql = $sql . "," . $v_is_view_on_net;
	$sql = $sql . "," . $v_is_register_on_net;
	
	//echo $sql.'<br>'; //exit;
	$ado_conn->SetFetchMode(ADODB_FETCH_NUM);
	$arr_all_recordtype = $ado_conn->GetAll($sql);
	//echo 'So recortype of staff :'.sizeof($arr_all_recordtype);
	//-------------------------------------------------------------------------------------------------------Leav_begin:14082008
	for($i=0;$i<sizeof($arr_all_recordtype);$i++){
		$_v_i = $arr_all_recordtype[$i];
		$_v_recordtype=	$_v_i[0];
		//thue		
		$sql = "Exec Onegate_RecordWorkSingleByRecordtype_leav_thue  ";
		$sql = $sql ."'" . $_v_recordtype . "'";
		$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
		$result_2 = $ado_conn->GetAll($sql);
		$v_size_2_thue=sizeof($result_2);
		$v_size_2=sizeof($result_2);
			if(sizeof($result_2)==1){
				$v_size_2_thue=sizeof($result_2);
				break;
			} 
	}

	for($i=0;$i<sizeof($arr_all_recordtype);$i++){
			$_v_i = $arr_all_recordtype[$i];
			$_v_recordtype=	$_v_i[0];
			//phat
			$sql = "Exec Onegate_RecordWorkSingleByRecordtype_leav_phat  ";
			$sql = $sql ."'" . $_v_recordtype . "'";
			$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
			$result_3 = $ado_conn->GetAll($sql);
			$v_size_2_phat=sizeof($result_3);
				if(sizeof($result_3)==1){
					$v_size_2_phat=sizeof($result_3);
					break;
				}
		}
	for($i=0;$i<sizeof($arr_all_recordtype);$i++){
			$_v_i = $arr_all_recordtype[$i];
			$_v_recordtype=	$_v_i[0];
			//phat
			$sql = "Exec Onegate_RecordWorkSingleByRecordtype_leav_khong_phat  ";
			$sql = $sql ."'" . $_v_recordtype . "'";
			$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
			$result_3 = $ado_conn->GetAll($sql);
			$v_size_2_khong_phat=sizeof($result_3);
				if(sizeof($result_3)==1){
					$v_size_2_khong_phat=sizeof($result_3);
					break;
				}
		}




//chuongnlt-begin 18/8/2008//
	for($i=0;$i<sizeof($arr_all_recordtype);$i++){
		$_v_i = $arr_all_recordtype[$i];
		$_v_recordtype=	$_v_i[0];
		
		$sql = "Exec Onegate_RecordWorkSingleByRecordtype_chuong2";
		$sql = $sql ."'" . $_v_recordtype . "'";
		//echo $sql;
		$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
		$result_chuong = $ado_conn->GetAll($sql);
		$v_size_chuong=sizeof($result_chuong);
		//echo '------chuong----'.$v_size_chuong;

	if(sizeof($result_chuong)>0){
		$v_size_chuong=sizeof($result_chuong);
		
		break;
	}
	
	}
	
	//chuongnlt-end 18/8/2008//
	//--begin--nieuvv--260808--loc ra danh sach chuc nang cua he thong ap dung cho tung loai ho so
	$sql = "exec Onegate_RecordWorkSingleByRecordtype_nieuvv '".$v_recordtype_filter . "'";
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$result_ = $ado_conn->GetAll($sql);
	$v_so_count = sizeof($result_);
	#echo $sql;
	//--the-end--nieuvv--260808---
	
	//Kiem tra xem co phai la chi lay cac ho so nam trong danh sach hay khong
	if ($v_recordtype_filter_list!=""){
		$j=0;
		$temp_all_recordtype = array();
		for ($i=0;$i< sizeof($arr_all_recordtype);$i++){
			if (_list_have_element($v_recordtype_filter_list,$arr_all_recordtype[$i]['0'],',')){
				$temp_all_recordtype[$j] = $arr_all_recordtype[$i];
				$j++;
			}
		}
		$arr_all_recordtype = $temp_all_recordtype;
	}
	//Khoi tao loai ho so
	if ($_SESSION['onegate_current_recordtype']==""||$_SESSION['onegate_current_recordtype']=="All"){
		$_SESSION['onegate_current_recordtype'] = "All";//$arr_all_recordtype[0][0];
	}else{
		$OK = true;
		for ($i=0;$i<sizeof($arr_all_recordtype);$i++){
			if ($_SESSION['onegate_current_recordtype'] == $arr_all_recordtype[$i][0]){
				$OK = false;				
			}
		}
		if ($OK && sizeof($arr_all_recordtype)>0){
			$_SESSION['onegate_current_recordtype'] = $arr_all_recordtype[0][0];
		}
	}	
	
}?>
